from urllib.request import urlretrieve
import requests
from bs4 import BeautifulSoup

def geturl(url):
    html=requests.get(url)
    html.encoding = 'gb2312'
    bs=BeautifulSoup(html.text,'html.parser')
    return bs

#子界面获取图片链接
def geturl2(url):
    bs=geturl(url)
    x=bs.find('p',{'style':'text-align: center;'}).find_all(src=True)
    t=1
    for y in x:
        urlretrieve(y['src'],'{}---{}'.format(bs.body.h1.get_text(),t))
        t+=1
        print('{}---{}---下载成功'.format(bs.body.h1.get_text(),t))

#首界面获取子界面链接
def geturl1(url):
    bs=geturl(url)
    x=bs.find('div',{'id':'gui_left'}).find_all('a',{'class':'preview'})
    for y in x:
        geturl2(y['href'])

#http://p.ik123.com/zt/loltp/
url=input('输入一个链接：')
geturl1(url)
